using System;
using System.Configuration;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Data;

namespace Googler.BLL
{
	public enum LayerType
	{
		DAL,
		BLL,
		PLL
	}
	
	public enum AdminMode
	{
		Add,
		Edit,
		Delete,
		GetAll,
	}	
	
	public class Globals
	{
        private static string strConnectionString;
		public Globals()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		//static public OleDbConnection Connection
		#region Data Base Data
        /// <summary>
        /// Returns Defualt Connention string from web configuration file
        /// </summary>
        /// <update>
        /// <developer Name="Mustafa Gamal" date="1-16-07">
        /// chenged ConnectionString to DefaultConnectionString, and reading it from connectionString section
        /// in config file if exist
        /// </developer>
        /// </update>
		static public string ConnectionString
		{
           
			get
			{
                if (strConnectionString != null)
                    return strConnectionString;
                strConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnectionString"].ConnectionString;
				//
				// If it not exist or if it empty
				//
				if (strConnectionString==null  || strConnectionString == String.Empty)
					throw (new ApplicationException("ConnectionString configuration is missing from you web.config. It should contain  <appSettings><add key=\"ConnectionString\" value=\"database=DatabaseName;...\" /></appSettings> "));
				else
					return strConnectionString;
				
			}
            set
            {
                strConnectionString = value;
            }
		}
		static public string DataAccessLayerType
		{
			get
			{
                string strDatabaseAccessLayerType = 
                    System.Configuration.ConfigurationManager.AppSettings["DatabaseAccessLayerType"];

				if( strDatabaseAccessLayerType == null || strDatabaseAccessLayerType  == string.Empty)
					throw (new ApplicationException("Database access layer type configuration is missing from you web.config. It should contain  <appSettings><add key=\"DatabaseAccessLayerType\" value=\"Database access layer type\" /></appSettings> "));
				return strDatabaseAccessLayerType;
			}
		}
		#endregion

        public static string GetConnectionString(string connectionStringKey)
        {
            ConfigurationSection section = (ConfigurationSection)System.Configuration.ConfigurationManager.GetSection("connectionStrings");
            if (section == null)
            {
                throw new Exception("<connectionStrings> Configuration Section is Missing from your Configuration File");
            }
            ConnectionStringSettings conStringSettings = System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringKey];
            if (conStringSettings == null)
            {
                throw new Exception("<add name=\"" + connectionStringKey + "\" connectionString=\"<< Your Connection Goes Here >>\" > is Missing from your connectionStrings Section in the Configuration File");
            }
            
            string str = conStringSettings.ConnectionString;

            if (str == null || str == string.Empty)
            {
                throw new Exception("<add name=\"" + connectionStringKey + "\" connectionString=\"<< Your Connection Goes Here >>\" > has no value in connectionStrings Section in the Configuration File");
            }

            return str;
        }
    }
}
